"""
    JSON:前后端交换格式
    XML:前后端交换格式

    Xpath : pip install xpath -i 镜像源
"""

from lxml import etree
s = """
<bookstore>
 
<book class="a">
  <title lang="eng">Harry Potter</title>
  <price>29.99</price>
</book>
 
<book class="b">
  <title lang="eng">Learning XML</title>
  <price>39.95</price>
</book>
 
</bookstore>

"""
# 能让Xpath识别的xml对象
html = etree.HTML(s)

# 提取
print(html.xpath("//book"))
print(html.xpath("//book/title"))
print(html.xpath("//book/title/text()"))
print(html.xpath("//book/price/text()"))
print(html.xpath("//book//text()"))
print(html.xpath("//book/title/@lang"))
print(html.xpath('//book[@class="b"]/title/@lang'))




